home *** CD-ROM | disk | FTP | other *** search
- Path: nwlink.com!usenet
- From: Teresa Reiko <tjr19@mail.nwlink.com>
- Newsgroups: comp.lang.c
- Subject: Re: Check if a file exists?
- Date: 15 Apr 1996 14:05:52 GMT
- Organization: Northwest Link
- Message-ID: <4ktl40$b76@texas.nwlink.com>
- References: <4kp7pg$upe@news-s01.ny.us.ibm.net>
- NNTP-Posting-Host: port55.annex2.nwlink.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.2 (Windows; U; 16bit)
-
- bfilone@ibm.net <Bruce Filone> wrote:
- >Is it possible in C to check if a file exists other than checking for a >succesful
- >fopen? ON a unix machine, I just want to know if a file is there or not, >do not
- >to read or write anything to it. similar to the -f test in unix? I was >hoping for
- >something less costly than opening and closing if exists because I am >checking
- >for the existance of many files during the run of a process
- >Did not see any postings that seemed to refer to this.
-
- Use rename():
-
- You could try to rename it, and if that fails it's not there,
- if it works it exists, and then you can rename it back.
-
- Or, you can create a temporary file, try to rename it to the
- name of the file you're testing, if it fails it exists, and
- if it works it wasn't there, and then you can rename it back.
-
- This should be faster than fopen, but you would need to have
- write access to all the files you're testing.
-
- ----- for every vision there is an equal and opposite revision ... -----
- ------------------------------------------------------------------------
- Teresa Reiko Chief Programmer, Tenbyte Software tjr19@nwlink.com
- ------------------------------------------------------------------------
-
-
-